/*
 * File Name:               ButtonExtension.cs
 *
 * Description:             普通类
 * Author:                  lisiyu <576603306@qq.com>
 * Create Date:             2016/11/23
 */

using UnityEngine.Events;
using UnityEngine.UI;

/// <summary>
/// UGUI按钮扩展 
/// </summary>
public static class ButtonExtension
{
    /// <summary>
    /// 添加按钮事件 
    /// </summary>
    /// <param name="button">  </param>
    /// <param name="callback"></param>
    public static void addListener(this Button button, UnityAction callback)
    {
        if (button == null)
            return;
        button.onClick.AddListener(callback);
    }

    /// <summary>
    /// 设置按钮事件 
    /// </summary>
    /// <param name="button">  </param>
    /// <param name="callback"></param>
    public static void setListener(this Button button, UnityAction callback)
    {
        if (button == null)
            return;
        button.onClick.RemoveAllListeners();
        button.addListener(callback);
    }

    /// <summary>
    /// 移除按钮事件 
    /// </summary>
    /// <param name="button">  </param>
    /// <param name="callback"></param>
    public static void removeListener(this Button button, UnityAction callback)
    {
        if (button == null)
            return;
        button.onClick.RemoveListener(callback);
    }

    /// <summary>
    /// 移除所有按钮事件 
    /// </summary>
    /// <param name="button"></param>
    public static void removeAllListeners(this Button button)
    {
        if (button == null)
            return;
        button.onClick.RemoveAllListeners();
    }
}